package ch.exploadingelephants.model;

import java.util.ArrayList;
import java.util.List;

import android.graphics.Point;

import com.exploadingelephants.R;

/**
 * @author Sandro De Zanet
 * 
 */
public enum ConveyorDirection {
    NORTH {
	@Override
	public List<Integer> getResourceIDs() {
	    List<Integer> result = new ArrayList<Integer>();
	    result.add(R.drawable.north_01);
	    result.add(R.drawable.north_02);
	    result.add(R.drawable.north_03);
	    result.add(R.drawable.north_04);
	    result.add(R.drawable.north_05);
	    result.add(R.drawable.north_06);
	    result.add(R.drawable.north_07);
	    result.add(R.drawable.north_08);
	    result.add(R.drawable.north_09);
	    result.add(R.drawable.north_10);
	    return result;
	}

	@Override
	public Point2D createPoint(Point2D startPoint) {
	    return new Point2D(startPoint.x, startPoint.y - 1);
	}

	@Override
	public ConveyorDirection turnLeft() {
	    return WEST;
	}

	@Override
	public ConveyorDirection turnRight() {
	    return EAST;
	}

	@Override
	public int getRbResourceID() {
	    return R.drawable.rb_north;
	}

	@Override
	public int getRwResourceID() {
	    return R.drawable.rw_north;
	}

	@Override
	public int getBwResourceID() {
	    return R.drawable.bw_north;
	}
    },
    WEST {
	@Override
	public List<Integer> getResourceIDs() {
	    List<Integer> result = new ArrayList<Integer>();
	    result.add(R.drawable.west_01);
	    result.add(R.drawable.west_02);
	    result.add(R.drawable.west_03);
	    result.add(R.drawable.west_04);
	    result.add(R.drawable.west_05);
	    result.add(R.drawable.west_06);
	    result.add(R.drawable.west_07);
	    result.add(R.drawable.west_08);
	    result.add(R.drawable.west_09);
	    result.add(R.drawable.west_10);
	    return result;
	}

	@Override
	public Point2D createPoint(Point2D startPoint) {
	    return new Point2D(startPoint.x - 1, startPoint.y);
	}

	@Override
	public ConveyorDirection turnLeft() {
	    return SOUTH;
	}

	@Override
	public ConveyorDirection turnRight() {
	    return NORTH;
	}

	@Override
	public int getRbResourceID() {
	    return R.drawable.rb_west;
	}

	@Override
	public int getRwResourceID() {
	    return R.drawable.rw_west;
	}

	@Override
	public int getBwResourceID() {
	    return R.drawable.bw_west;
	}
    },
    SOUTH {
	@Override
	public List<Integer> getResourceIDs() {
	    List<Integer> result = new ArrayList<Integer>();
	    result.add(R.drawable.south_01);
	    result.add(R.drawable.south_02);
	    result.add(R.drawable.south_03);
	    result.add(R.drawable.south_04);
	    result.add(R.drawable.south_05);
	    result.add(R.drawable.south_06);
	    result.add(R.drawable.south_07);
	    result.add(R.drawable.south_08);
	    result.add(R.drawable.south_09);
	    result.add(R.drawable.south_10);
	    return result;
	}

	@Override
	public Point2D createPoint(Point2D startPoint) {
	    return new Point2D(startPoint.x, startPoint.y + 1);
	}

	@Override
	public ConveyorDirection turnLeft() {
	    return EAST;
	}

	@Override
	public ConveyorDirection turnRight() {
	    return WEST;
	}

	@Override
	public int getRbResourceID() {
	    return R.drawable.rb_south;
	}

	@Override
	public int getRwResourceID() {
	    return R.drawable.rw_south;
	}

	@Override
	public int getBwResourceID() {
	    return R.drawable.bw_south;
	}
    },
    EAST {
	@Override
	public List<Integer> getResourceIDs() {
	    List<Integer> result = new ArrayList<Integer>();
	    result.add(R.drawable.east_01);
	    result.add(R.drawable.east_02);
	    result.add(R.drawable.east_03);
	    result.add(R.drawable.east_04);
	    result.add(R.drawable.east_05);
	    result.add(R.drawable.east_06);
	    result.add(R.drawable.east_07);
	    result.add(R.drawable.east_08);
	    result.add(R.drawable.east_09);
	    result.add(R.drawable.east_10);
	    return result;
	}

	@Override
	public Point2D createPoint(Point2D startPoint) {
	    return new Point2D(startPoint.x + 1, startPoint.y);
	}

	@Override
	public ConveyorDirection turnLeft() {
	    return NORTH;
	}

	@Override
	public ConveyorDirection turnRight() {
	    return SOUTH;
	}

	@Override
	public int getRbResourceID() {
	    return R.drawable.rb_east;
	}

	@Override
	public int getRwResourceID() {
	    return R.drawable.rw_east;
	}

	@Override
	public int getBwResourceID() {
	    return R.drawable.bw_east;
	}
    };

    /**
     * @return
     */
    public abstract List<Integer> getResourceIDs();

    /**
     * @param diff
     * @return
     */
    public static ConveyorDirection getDirection(Point diff) {
	if (diff.x < 0) {
	    return WEST;
	} else if (diff.x > 0) {
	    return EAST;
	} else if (diff.y > 0) {
	    return SOUTH;
	} else
	    return NORTH;
    }

    /**
     * @param startPoint
     * @return
     */
    public abstract Point2D createPoint(Point2D startPoint);

    /**
     * @return
     */
    public abstract ConveyorDirection turnLeft();

    /**
     * @return
     */
    public abstract ConveyorDirection turnRight();

    /**
     * @return
     */
    public abstract int getRbResourceID();

    /**
     * @return
     */
    public abstract int getRwResourceID();

    /**
     * @return
     */
    public abstract int getBwResourceID();

}
